﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using TestTreeView.Model;
using MSSClient.Utils;
using System.IO;
using System.Xml;

namespace MSSClient.Model
{
    /// <summary>
    /// 全局变量类
    /// </summary>
    class Global
    {
        //单例模式
        private static Global m_Instance = null;

        //只能存在一个实例对象
        public static Global getInstance()
        {
            if(null == m_Instance)
            {
                m_Instance = new Global();
            }
            return m_Instance;
        }
        public LoginData loginData;
        public CanUploadData canUploadData;
        public SyncUploadResultData syncUploadResultData;
        public UpGradeModel getOCRTrigger;
        public int SourceListPos = 0;
        public long qualityValue = 50;

        // 服务端接口
        public string strLogin = "login";//登录
        public string strCanUpload = "canUpload";//获取是否能上传信息
        public string strSyncUpload = "syncUploadResult";//获取上传结果
        public string strNewVersion = "getVersion";//获取更新版本号
        public string strOCRTrigger = "getOCRTrigger";//获取ocr区分发票开关
        public string strgetCLient = "getClient";//获取客户端
        public string strBuDanInfo = "getBuDanInfo";//获取补单任务信息
        public string strGetImageList = "getBuDanImages";//获取补单任务影像
        public string strGetFtpInfo = "getFtpInfo";//获取补单任务影像

        public string strConfigFileName = "config.ini";//设置结果保存
        public string strUrl = readUrl();//读取app.config配置文件
        public string version = ConfigurationManager.AppSettings["version"];//读取app.config配置文件
        public string sysTypeCode = "";
        public string strScannedDic = "Scannned\\";//扫描图片保存文件夹名称
        public string strUploadedDic = "Uploaded\\";//上传图片保存文件夹名称

        public static String readUrl()
        {
            String loginUrl = "";
            try
            {
                if (File.Exists("C:\\MssClientCache\\urlSetting.xml"))
                {
                    XmlDocument MyXml = new XmlDocument();
                    MyXml.Load("C:\\MssClientCache\\urlSetting.xml");
                    //获取<configuration>节点的所有子节点
                    XmlNodeList MyNodeList = MyXml.SelectSingleNode("appSettings").ChildNodes;

                    //遍历<configuration>下的所有子节点
                    foreach (XmlNode MyNode in MyNodeList)
                        loginUrl = MyNode.Attributes["value"].Value;
                }
                else
                    loginUrl = ConfigurationManager.AppSettings["strUrl"];
            }
            catch (Exception ex)
            {
                loginUrl = ConfigurationManager.AppSettings["strUrl"];
                CommonUtil.WriteLog(ex);
                return loginUrl;
            }
            return loginUrl;
        }
    }
}
